

//
//  YZQ24HourFirstTableViewCell.m
//  SuperNews
//
//  Created by qiang on 16/1/13.
//  Copyright © 2016年 qiang. All rights reserved.
//

#import "YZQ24HourFirstTableViewCell.h"

@implementation YZQ24HourFirstTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubView];
    }
    return self;
}

- (void)createSubView {
    
    //    // 图片
    self.imageV = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width - 20 * SMALLSCREEN_WIDTH, 170)];
    self.imageV.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:self.imageV];
    //
    // 标题
    self.titleL = [[UILabel alloc] initWithFrame:CGRectMake(10, self.imageV.frame.size.height + 15, self.imageV.frame.size.width, 25)];
    self.titleL.font = [UIFont systemFontOfSize:18];
    [self.contentView addSubview:self.titleL];
    //
    //
    //    // 详情
    self.digestL = [[UILabel alloc] initWithFrame:CGRectMake(10, self.imageV.frame.size.height + self.titleL.frame.size.height + 10, self.titleL.frame.size.width, 50)];
    self.digestL.font = [UIFont systemFontOfSize:14];
    self.digestL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    self.digestL.numberOfLines = 0;
    [self.contentView addSubview:self.digestL];
    
    //    // 跟贴
    self.replyF = [[UITextField alloc] initWithFrame:CGRectMake(300 * SMALLSCREEN_WIDTH, 170 * SMALLSCREEN_HEIGHT, 70 * SMALLSCREEN_WIDTH, 15)];
    // 设置文字的对齐方式
    self.replyF.textAlignment = NSTextAlignmentCenter;
    self.replyF.borderStyle = UITextBorderStyleRoundedRect;
    self.replyF.userInteractionEnabled = NO;
    self.replyF.textColor = [UIColor lightGrayColor];
    self.replyF.borderStyle = UITextBorderStyleRoundedRect;
    self.replyF.font = [UIFont systemFontOfSize:11];
    [self.contentView addSubview:self.replyF];
    //
    //右上角new
    self.newsImageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"subscription_topic_new@2x.png"]];
    self.newsImageV.frame = CGRectMake(316 * SMALLSCREEN_WIDTH, 15, 44 * SMALLSCREEN_WIDTH , 22);
    [self.contentView addSubview:self.newsImageV];
    
    //左下角角标
    self.numImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"todaynews_cell_tag@2x.png"]];
    self.numImageV.frame = CGRectMake(10, 160, 26, 20);
    [self.contentView addSubview:self.numImageV];
    
    //左下角角标数字
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 160, 20, 20)];
    self.numLabel.textAlignment = NSTextAlignmentCenter;
    self.numLabel.font = [UIFont systemFontOfSize:14];
    self.numLabel.textColor = [UIColor whiteColor];
    self.numLabel.text = @"1";
    [self.contentView addSubview:self.numLabel];
    
    
}

-(void)setModel:(NewsPageModel *)model
{
    _model = model;
    // 标题
    self.titleL.text = model.title;
    // 图片
    NSURL *url = [NSURL URLWithString:model.imgsrc];
    [self.imageV sd_setImageWithURL:url placeholderImage:nil];
    // 简介
    self.digestL.text = model.digest;
    // 跟贴
    CGFloat replayC = [self.model.replyCount floatValue];
    if (replayC > 0) {
        NSString *replayStr = [NSString stringWithFormat:@"%.0f跟帖", replayC];
        if (replayC >= 10000 ) {
            replayStr = [NSString stringWithFormat:@"%.1f万跟帖", replayC / 10000];
        }
        NSInteger lenth = replayStr.length;
        CGFloat w = (lenth + 2) * 8.0 + 5;
        CGRect temp = self.replyF.frame;
        temp.size.width = w;
        self.replyF.frame = temp;
        self.replyF.center = CGPointMake(330 * SMALLSCREEN_WIDTH, 250 * SMALLSCREEN_HEIGHT);
        self.replyF.text = replayStr;
        
    } else {
        
        self.replyF.borderStyle = UITextBorderStyleNone;
    }
}



@end
